package com.chaos.auth.service.oauth;

import com.chaos.auth.api.data.oauth.OauthApprovalsData;
import com.chaos.auth.entity.OauthApprovals;
import com.chaos.auth.mapper.OauthApprovalsMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chaos.framework.model.dto.page.PageList;
import com.chaos.framework.model.dto.page.PageQueryDto;
import com.chaos.framework.model.entity.Table;
import com.chaos.framework.model.helper.ConvertHelper;
import com.chaos.framework.model.helper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Jacky
 * @since 2024-05-07
 */
@Slf4j
@Component
public class OauthApprovalsService extends ServiceImpl<OauthApprovalsMapper, OauthApprovals> {

    public void insertModel(OauthApprovalsData data) {
        OauthApprovals entity = ConvertHelper.convert(data, OauthApprovals.class);
        save(entity);
    }

    public List<OauthApprovalsData> selectByData(OauthApprovalsData data) {
        QueryWrapper<OauthApprovals> query = new QueryWrapper();
        query.orderByDesc(Table.ID);
        return ConvertHelper.convert(list(query), OauthApprovalsData.class);
    }

    public PageList<OauthApprovalsData> selectByPage(PageQueryDto<OauthApprovalsData> pageData) {
        QueryWrapper<OauthApprovals> query = new QueryWrapper();
        query.orderByDesc(Table.ID);
        return PageHelper.pageList(page(PageHelper.page(pageData), query), OauthApprovalsData.class);
    }

}
